package sg.edu.nus.iss.team2s.jass.gui;

import java.awt.Frame;
import java.awt.TextField;
import java.awt.Rectangle;
import java.awt.Button;

import sg.edu.nus.iss.team2s.jass.control.LoginController;
import sg.edu.nus.iss.team2s.jass.dto.User;
import java.awt.Label;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginScreen extends Frame implements ActionListener {

	private static final long serialVersionUID = 1L;
	private TextField txt_userName = null;
	private TextField txt_password = null;
	private Button cmd_login = null;
	private Label lbl_userName = null;
	private Label lbl_title = null;
	private Label lbl_password = null;
	private Button cmd_cancel = null;

	/**
	 * This is the default constructor
	 */
	public LoginScreen() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		lbl_password = new Label();
		lbl_password.setBounds(new Rectangle(123, 175, 81, 30));
		lbl_password.setText("Password:");
		lbl_title = new Label();
		lbl_title.setBounds(new Rectangle(123, 55, 345, 41));
		lbl_title.setText("Welcome to Job Advertisement and Search System");
		Font titleFont = new Font("Serif", Font.BOLD, 15);
		lbl_title.setFont(titleFont);
		lbl_userName = new Label();
		lbl_userName.setBounds(new Rectangle(123, 128, 81, 30));
		lbl_userName.setText("User Name:");
		this.setLayout(null);
		this.setSize(588, 289);
		this.setTitle("JASS Login");

		this.add(getTxt_userName(), null);
		this.add(getTxt_password(), null);
		this.add(getCmd_login(), null);
		this.add(lbl_userName, null);
		this.add(lbl_title, null);
		this.add(lbl_password, null);
		this.add(getCmd_cancel(), null);
		//centralize the window
		//
	}

	/**
	 * This method initializes txt_userName	
	 * 	
	 * @return java.awt.TextField	
	 */
	private TextField getTxt_userName() {
		if (txt_userName == null) {
			txt_userName = new TextField();
			txt_userName.setBounds(new Rectangle(218, 129, 252, 26));
		}
		return txt_userName;
	}

	/**
	 * This method initializes txt_password	
	 * 	
	 * @return java.awt.TextField	
	 */
	private TextField getTxt_password() {
		if (txt_password == null) {
			txt_password = new TextField();
			txt_password.setBounds(new Rectangle(218, 175, 252, 26));
		}
		return txt_password;
	}

	/**
	 * This method initializes cmd_login	
	 * 	
	 * @return java.awt.Button	
	 */
	private Button getCmd_login() {
		if (cmd_login == null) {
			cmd_login = new Button("Login");
			cmd_login.setBounds(new Rectangle(290, 227, 79, 26));
			cmd_login.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					validate("", "");
//					if(LoginScreen.this.callBack == null){
//						LoginScreen.this.callBack = new JobAdvertMainScreen();
//					}
//					LoginScreen.this.callBack.setUser(user);
				}
			});
		}
		return cmd_login;
	}
	
	private boolean validate(String userName, String passWord){
		return LoginController.validateLogin(userName, passWord);
		
	}

	/**
	 * This method initializes cmd_cancel	
	 * 	
	 * @return java.awt.Button	
	 */
	private Button getCmd_cancel() {
		if (cmd_cancel == null) {
			cmd_cancel = new Button("Main Screen");
			cmd_cancel.setBounds(new Rectangle(391, 227, 79, 26));
		}
		return cmd_cancel;
	}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}

}  //  @jve:decl-index=0:visual-constraint="37,18"
